﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class CargoDao
    Inherits DAO(Of Cargo)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"

    Protected Overrides Sub ValidarInsert(modelo As Cargo)

        Dim NHQL As String = "from Cargo where Nome  = '" & modelo.Nome & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Cargo com esse Nome")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(modelo As Cargo)

    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As Cargo)

        Dim NHQL As String = "from Cargo as c where c.Nome  = '" & modelo.Nome & "' AND c.CargoId != " & modelo.CargoId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Cargo com esse Nome")
        End If

    End Sub

#End Region
End Class
